package com.portal.cwegportal.controller;

import com.appcenter.jz.Logger.BusinessLogger;
import com.appcenter.jz.Logger.LoggerGenre;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import com.portal.cwegportal.input.meeting.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/portal/meeting")
@Api(description = "会议API")
public class MeetingController {

    @Autowired
    com.portal.cwegportal.service.MeetingService meetingService;

    @ApiOperation(value = "创建会议", notes = "创建会议", produces = "application/json")
    @PostMapping("/createMeeting")
    public ResponseEntity<JsonResult> createMeeting(@RequestBody CreateMeetingInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"创建会议",input);
        JsonResult r = new JsonResult();

        try {
            r.setResult(meetingService.createMeeting(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "删除会议", notes = "删除会议",produces = "application/json")
    @PostMapping("/deleteMeeting")
    public ResponseEntity<JsonResult> deleteMeeting(@RequestBody DeleteMeetingInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"删除会议",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(meetingService.deleteMeeting(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "修改会议", notes = "修改会议",produces = "application/json")
    @PostMapping("/editMeeting")
    public ResponseEntity<JsonResult> editMeeting(@RequestBody EditMeetingInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"修改会议",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(meetingService.editMeeting(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "根据会议ID获取会议信息(我发出的通知)", notes = "根据会议ID获取会议信息(我发出的通知)",produces = "application/json")
    @PostMapping("/getMeetingByMe")
    public ResponseEntity<JsonResult> getMeetingByMe(@RequestBody GetMeetingInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"根据会议ID获取会议信息(我发出的通知)",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(meetingService.getMeetingsByMe(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "根据会议ID获取会议信息(发给我的通知)", notes = "根据会议ID获取会议信息(发给我的通知)",produces = "application/json")
    @PostMapping("/getMeetingToMe")
    public ResponseEntity<JsonResult> getMeetingToMe(@RequestBody GetMeetingInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"根据会议ID获取会议信息(发给我的通知)",input);
        JsonResult r = new JsonResult();

        try {
            r.setResult(meetingService.getMeetingsToMe(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }

        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "加载会议通知列表（發給我的）", notes = "加载会议通知列表（發給我的）",produces = "application/json")
    @PostMapping("/pageLoadMeetingListToMe")
    public ResponseEntity<JsonResult> pageLoadMeetingListToMe(@RequestBody PageLoadMeetingInput input) throws Exception {
        BusinessLogger.Info( LoggerGenre.Add,"加载会议通知列表（發給我的）",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(meetingService.pageLoadMeetingListToMe(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "加载会议通知列表（我发出的）", notes = "加载会议通知列表（我发出的）",produces = "application/json")
    @PostMapping("/pageLoadMeetingListByMe")
    public ResponseEntity<JsonResult> pageLoadMeetingListByMe(@RequestBody PageLoadMeetingInput input) throws Exception {
        BusinessLogger.Info( LoggerGenre.Add,"加载会议通知列表（我发出的）",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(meetingService.pageLoadMeetingListByMe(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "根据时间和人获取会议信息", notes = "加载会议信息",produces = "application/json")
    @PostMapping("/getMettingByTimeUser")
    public ResponseEntity<JsonResult> getMettingByTimeUser(@RequestBody GetMettingByTimeUserInput input) throws Exception {
        BusinessLogger.Info( LoggerGenre.Add,"根据时间和人获取会议信息",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(meetingService.getMettingByTimeUser(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "传入回复信息项", notes = "更新回复内容",produces = "application/json")
    @PostMapping("/replyMettingNotice")
    public ResponseEntity<JsonResult> replyMettingNotice(@RequestBody ReplyMeetingNoticeInput input) throws Exception {
        BusinessLogger.Info( LoggerGenre.Add,"回复信息项",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(meetingService.replyMettingNotice(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "传入确认回复信息项", notes = "更新确认回复内容",produces = "application/json")
    @PostMapping("/ronfirmReplyMettingNotice")
    public ResponseEntity<JsonResult> confirmReplyMettingNotice(@RequestBody ConfirmReplyCategoryInput input) throws Exception {
        BusinessLogger.Info( LoggerGenre.Add,"确认回复信息项",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(meetingService.confirmReplyMettingNotice(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

}
